from rest_framework.throttling import UserRateThrottle
from rest_framework.permissions import BasePermission, IsAuthenticated
from rest_framework.pagination import PageNumberPagination
from django_filters import filterset, filters


class CodeThrottle(UserRateThrottle):
    rate = "1/minute"


class SVIPPermission(BasePermission):
    def has_permission(self, request, view):
        if request.user.is_authenticated and request.user.type == 3:
            return True
        else:
            return False


class HeroPage(PageNumberPagination):
    page_size = 2


class HeroThrottle(UserRateThrottle):
    rate = "5/minute"


class HeroFilterSet(filterset.FilterSet):
    minage = filters.NumberFilter(field_name="age", lookup_expr="gte", label="最小值")
    maxage = filters.NumberFilter(field_name="age", lookup_expr="lte", label="最大值")
